package com.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.entity.Tag;
import com.mapper.TagMapper;
import com.service.TagService;

@Service
public class TagServiceImpl implements TagService{

	@Resource
	private TagMapper tagMapper;
	
	@Cacheable(value = "cacheArticle")
	public List<Tag> listTag() {
		
		return tagMapper.listTag();
	}
	@Cacheable(value = "cacheArticle",key="'tag_'+#id")
	public List<Tag> getTagById(Integer id) {
	
		return tagMapper.getTagById(id);
	}

	
	public List<Tag> listCountTag() {
		List<Tag>  tag = tagMapper.listTag();
		for(Tag t:tag) {
			Integer tagid = t.getTagId();
			Integer countArticle = tagMapper.CountArticle(tagid);
			t.setArticleCount(countArticle);
		}
		
		return tag;
	}

	public void addTag(Tag tag) {
		tagMapper.addTag(tag);
		
	}

	public void deleteTag(Integer id) {
		tagMapper.deleteTag(id);
		
	}

	
	public Tag getTagsById(Integer id) {
		return tagMapper.getTagsById(id);
	}


}











